DROP DATABASE IF EXISTS cloud1;

CREATE DATABASE cloud1 CHARACTER SET UTF8;

USE cloud1;
DROP TABLE IF EXISTS `dept`;
CREATE TABLE `dept`
(
    `dept_no`   int NOT NULL AUTO_INCREMENT,
    `dept_name` varchar(255) DEFAULT NULL,
    `db_source` varchar(255) DEFAULT NULL,
    PRIMARY KEY (`dept_no`)
) ENGINE = InnoDB
  AUTO_INCREMENT = 6
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_0900_ai_ci;


INSERT INTO `dept`
VALUES ('1', '开发部', DATABASE());
INSERT INTO `dept`
VALUES ('2', '人事部', DATABASE());
INSERT INTO `dept`
VALUES ('3', '财务部', DATABASE());
INSERT INTO `dept`
VALUES ('4', '市场部', DATABASE());
INSERT INTO `dept`
VALUES ('5', '运维部', DATABASE());


#######################################################


DROP DATABASE IF EXISTS cloud2;

CREATE DATABASE cloud2 CHARACTER SET UTF8;

USE cloud2;
DROP TABLE IF EXISTS `dept`;
CREATE TABLE `dept`
(
    `dept_no`   int NOT NULL AUTO_INCREMENT,
    `dept_name` varchar(255) DEFAULT NULL,
    `db_source` varchar(255) DEFAULT NULL,
    PRIMARY KEY (`dept_no`)
) ENGINE = InnoDB
  AUTO_INCREMENT = 6
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_0900_ai_ci;


INSERT INTO `dept`
VALUES ('1', '开发部', DATABASE());
INSERT INTO `dept`
VALUES ('2', '人事部', DATABASE());
INSERT INTO `dept`
VALUES ('3', '财务部', DATABASE());
INSERT INTO `dept`
VALUES ('4', '市场部', DATABASE());
INSERT INTO `dept`
VALUES ('5', '运维部', DATABASE());


#######################################################
DROP DATABASE IF EXISTS seata;

CREATE DATABASE seata CHARACTER SET UTF8;

USE seata;

-- the table to store GlobalSession data
CREATE TABLE IF NOT EXISTS `global_table`
(
    `xid`                       VARCHAR(128) NOT NULL,
    `transaction_id`            BIGINT,
    `status`                    TINYINT      NOT NULL,
    `application_id`            VARCHAR(32),
    `transaction_service_group` VARCHAR(32),
    `transaction_name`          VARCHAR(128),
    `timeout`                   INT,
    `begin_time`                BIGINT,
    `application_data`          VARCHAR(2000),
    `gmt_create`                DATETIME,
    `gmt_modified`              DATETIME,
    PRIMARY KEY (`xid`),
    KEY `idx_gmt_modified_status` (`gmt_modified`, `status`),
    KEY `idx_transaction_id` (`transaction_id`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8;


-- the table to store BranchSession data
CREATE TABLE IF NOT EXISTS `branch_table`
(
    `branch_id`         BIGINT       NOT NULL,
    `xid`               VARCHAR(128) NOT NULL,
    `transaction_id`    BIGINT,
    `resource_group_id` VARCHAR(32),
    `resource_id`       VARCHAR(256),
    `branch_type`       VARCHAR(8),
    `status`            TINYINT,
    `client_id`         VARCHAR(64),
    `application_data`  VARCHAR(2000),
    `gmt_create`        DATETIME(6),
    `gmt_modified`      DATETIME(6),
    PRIMARY KEY (`branch_id`),
    KEY `idx_xid` (`xid`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8;

-- the table to store lock data
CREATE TABLE IF NOT EXISTS `lock_table`
(
    `row_key`        VARCHAR(128) NOT NULL,
    `xid`            VARCHAR(96),
    `transaction_id` BIGINT,
    `branch_id`      BIGINT       NOT NULL,
    `resource_id`    VARCHAR(256),
    `table_name`     VARCHAR(32),
    `pk`             VARCHAR(36),
    `gmt_create`     DATETIME,
    `gmt_modified`   DATETIME,
    PRIMARY KEY (`row_key`),
    KEY `idx_branch_id` (`branch_id`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8;

-- ----------------------------
-- Table structure for distributed_lock
-- ----------------------------
DROP TABLE IF EXISTS `distributed_lock`;
CREATE TABLE `distributed_lock`
(
    `lock_key`   char(20)    NOT NULL,
    `lock_value` varchar(20) NOT NULL,
    `expire`     bigint(20) DEFAULT NULL,
    PRIMARY KEY (`lock_key`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4;

-- ----------------------------
-- Records of distributed_lock
-- ----------------------------
BEGIN;
INSERT INTO `distributed_lock`
VALUES ('AsyncCommitting', ' ', 0);
INSERT INTO `distributed_lock`
VALUES ('RetryCommitting', ' ', 0);
INSERT INTO `distributed_lock`
VALUES ('RetryRollbacking', ' ', 0);
INSERT INTO `distributed_lock`
VALUES ('TxTimeoutCheck', ' ', 0);
INSERT INTO `distributed_lock`
VALUES ('UndologDelete', ' ', 0);
COMMIT;

#######################################################


DROP DATABASE IF EXISTS 'seata-order';

CREATE DATABASE 'seata-order' CHARACTER SET UTF8;

USE 'seata-order';

DROP TABLE IF EXISTS `t_order`;
CREATE TABLE `t_order`
(
    `id`         bigint NOT NULL AUTO_INCREMENT,
    `user_id`    bigint         DEFAULT NULL COMMENT '用户id',
    `product_id` bigint         DEFAULT NULL COMMENT '产品id',
    `count`      int            DEFAULT NULL COMMENT '数量',
    `money`      decimal(11, 0) DEFAULT NULL COMMENT '金额',
    `status`     int            DEFAULT NULL COMMENT '订单状态：0：未完成；1：已完结',
    PRIMARY KEY (`id`)
) ENGINE = InnoDB
  AUTO_INCREMENT = 32
  DEFAULT CHARSET = utf8;

-- ----------------------------
-- Table structure for undo_log
-- ----------------------------
DROP TABLE IF EXISTS `undo_log`;
CREATE TABLE `undo_log`
(
    `branch_id`     bigint       NOT NULL COMMENT 'branch transaction id',
    `xid`           varchar(128) NOT NULL COMMENT 'global transaction id',
    `context`       varchar(128) NOT NULL COMMENT 'undo_log context,such as serialization',
    `rollback_info` longblob     NOT NULL COMMENT 'rollback info',
    `log_status`    int          NOT NULL COMMENT '0:normal status,1:defense status',
    `log_created`   datetime(6)  NOT NULL COMMENT 'create datetime',
    `log_modified`  datetime(6)  NOT NULL COMMENT 'modify datetime',
    UNIQUE KEY `ux_undo_log` (`xid`, `branch_id`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8;


#######################################################

DROP TABLE IF EXISTS `t_storage`;
CREATE TABLE `t_storage`
(
    `id`         bigint NOT NULL AUTO_INCREMENT,
    `product_id` bigint DEFAULT NULL COMMENT '产品id',
    `total`      int    DEFAULT NULL COMMENT '总库存',
    `used`       int    DEFAULT NULL COMMENT '已用库存',
    `residue`    int    DEFAULT NULL COMMENT '剩余库存',
    PRIMARY KEY (`id`)
) ENGINE = InnoDB
  AUTO_INCREMENT = 2
  DEFAULT CHARSET = utf8;

-- ----------------------------
-- Records of t_storage
-- ----------------------------
INSERT INTO `t_storage`
VALUES ('1', '1', '100', '0', '100');

-- Table structure for undo_log
-- ----------------------------
DROP TABLE IF EXISTS `undo_log`;
CREATE TABLE `undo_log`
(
    `branch_id`     bigint       NOT NULL COMMENT 'branch transaction id',
    `xid`           varchar(128) NOT NULL COMMENT 'global transaction id',
    `context`       varchar(128) NOT NULL COMMENT 'undo_log context,such as serialization',
    `rollback_info` longblob     NOT NULL COMMENT 'rollback info',
    `log_status`    int          NOT NULL COMMENT '0:normal status,1:defense status',
    `log_created`   datetime(6)  NOT NULL COMMENT 'create datetime',
    `log_modified`  datetime(6)  NOT NULL COMMENT 'modify datetime',
    UNIQUE KEY `ux_undo_log` (`xid`, `branch_id`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8 COMMENT ='AT transaction mode undo table';

#######################################################

DROP TABLE IF EXISTS `t_account`;
CREATE TABLE `t_account`
(
    `id`      bigint NOT NULL AUTO_INCREMENT COMMENT 'id',
    `user_id` bigint         DEFAULT NULL COMMENT '用户id',
    `total`   decimal(10, 0) DEFAULT NULL COMMENT '总额度',
    `used`    decimal(10, 0) DEFAULT NULL COMMENT '已用余额',
    `residue` decimal(10, 0) DEFAULT '0' COMMENT '剩余可用额度',
    PRIMARY KEY (`id`)
) ENGINE = InnoDB
  AUTO_INCREMENT = 2
  DEFAULT CHARSET = utf8;

-- ----------------------------
-- Records of t_account
-- ----------------------------
INSERT INTO `t_account`
VALUES ('1', '1', '1000', '0', '1000');

-- ----------------------------
-- Table structure for undo_log
-- ----------------------------
DROP TABLE IF EXISTS `undo_log`;
CREATE TABLE `undo_log`
(
    `branch_id`     bigint       NOT NULL COMMENT 'branch transaction id',
    `xid`           varchar(128) NOT NULL COMMENT 'global transaction id',
    `context`       varchar(128) NOT NULL COMMENT 'undo_log context,such as serialization',
    `rollback_info` longblob     NOT NULL COMMENT 'rollback info',
    `log_status`    int          NOT NULL COMMENT '0:normal status,1:defense status',
    `log_created`   datetime(6)  NOT NULL COMMENT 'create datetime',
    `log_modified`  datetime(6)  NOT NULL COMMENT 'modify datetime',
    UNIQUE KEY `ux_undo_log` (`xid`, `branch_id`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8;